package cn.liontalk.FlyweightPattern.complex;

import cn.liontalk.FlyweightPattern.Crayon;
import cn.liontalk.FlyweightPattern.ICrayon;

import java.util.HashMap;
import java.util.Map;

/**
 * 笔袋
 */
public class CrayonFactory {

    private static Map<String, ICrayon> data = new HashMap<>();

    public static ICrayon getCrayon(String color) {
        if (data.containsKey(color)) {
            return data.get(color);
        }
        ICrayon crayon = new Crayon(color);
        data.put(color, crayon);
        return crayon;
    }

}
